import Vue from "vue";
import Router from "vue-router";
import Login from "./modules/login.vue";
import Home from "./modules/Home.vue";
import hourseBaseInfo from "./modules/hourseBaseInfo.vue";
import hourseEstateInfo from "./modules/hourseEstateInfo.vue";
import hourseOpeningInfo from "./modules/hourseOpeningInfo.vue";
import hoursePresaleInfo from "./modules/hoursePresaleInfo.vue";
import hourseSaleInfo from "./modules/hourseSaleInfo.vue";
import hourseList from "./modules/hourseList.vue";
import hourseImage from "./modules/hourseImage.vue";
import newsList from "./modules/newsList.vue";
import newsInfo from "./modules/newsInfo.vue";
import subscribeList from "./modules/subscribeList.vue";
import subscribeInfo from "./modules/subscribeInfo.vue";

Vue.use(Router);


let router = new Router({
    mode: "history",
    base: "/",
    routes: [
        {
            path: "/login",
            name: "Login",
            component: Login
        },
        {
            path: "/",
            component: Home,
            meta: { pageName: "概览" },
            children:[
                {
                    path: "/hourseBaseInfo/:hourseId",
                    name: "hourseBaseInfo",
                    meta: { pageName: "基本信息" },
                    component: hourseBaseInfo
                },
                {
                    path: "/addHourseInfo",
                    name: "addHourseInfo",
                    meta: { pageName: "新增楼盘" },
                    component: hourseBaseInfo
                },
                {
                    path: "/hourseEstateInfo/:hourseId",
                    name: "hourseEstateInfo",
                    meta: { pageName: "小区信息" },
                    component: hourseEstateInfo
                },
                {
                    path: "/hourseOpeningInfo/:hourseId",
                    name: "hourseOpeningInfo",
                    meta: { pageName: "开盘信息" },
                    component: hourseOpeningInfo
                },
                {
                    path: "/hoursePresaleInfo/:hourseId",
                    name: "hoursePresaleInfo",
                    meta: { pageName: "预售许可证信息" },
                    component: hoursePresaleInfo
                },
                {
                    path: "/hourseSaleInfo/:hourseId",
                    name: "hourseSaleInfo",
                    meta: { pageName: "销售信息" },
                    component: hourseSaleInfo
                },
                {
                    path: "/hourseList",
                    name: "hourseList",
                    meta: { pageName: "楼盘列表" },
                    component: hourseList
                },
                {
                    path: "/hourseImage/:hourseId",
                    name: "hourseImage",
                    meta: { pageName: "图片管理" },
                    component: hourseImage
                },
                {
                    path: "/newsList",
                    name: "newsList",
                    meta: { pageName: "资讯列表" },
                    component: newsList
                },
                {
                    path: "/newsInfo/:newsId",
                    name: "newsInfo",
                    meta: { pageName: "新增资讯" },
                    component: newsInfo
                },
                {
                    path: "/addNewsInfo",
                    name: "addNewsInfo",
                    meta: { pageName: "新增资讯" },
                    component: newsInfo
                },
                {
                    path: "/subscribeList",
                    name: "subscribeList",
                    meta: { pageName: "预约看房列表" },
                    component: subscribeList
                },
                {
                    path: "/subscribeInfo/:subscribeId",
                    name: "subscribeInfo",
                    meta: { pageName: "预约看房信息" },
                    component: subscribeInfo
                }
            ]
        }
    ]
});


router.beforeEach((to, from, next) => {
    if(to.name == 'Login'){
        next();
    }else{
        if (!JSON.parse(window.sessionStorage.getItem('user'))) {
            next({
              path: '/login'
            });
        }else{
            next();
        }
    }
});

export default router;